package com.example.controller;

import com.example.pojo.*;
import com.example.service.ArticlesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/articles")
public class ArticlesController {
    @Autowired
    private ArticlesService articlesService;
    @GetMapping
    public Result page(ArticleQueryParam articleQueryParam){
        log.info("查询参数: {}", articleQueryParam);
        PageResult<Articles> pageResult= articlesService.page(articleQueryParam);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result add(@RequestBody Articles articles){
        log.info("新增文章"+articles);
        articlesService.Add(articles);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据ID查询"+id);
        Articles articles= articlesService.GetById(id);
        return Result.success(articles);
    }
    @PutMapping
    public Result update(@RequestBody Articles articles){
        log.info("修改部门"+articles);
        articlesService.update(articles);
        return Result.success();
    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("删除员工{}", ids);
        articlesService.delete(ids);
        return Result.success();
    }
    @GetMapping("/latestArticles")
    public Result page2(ArticleQueryParam articleQueryParam){
        log.info("查询参数: {}", articleQueryParam);
        PageResult<Articles> pageResult= articlesService.page2(articleQueryParam);
        return Result.success(pageResult);
    }
}
